package com.ny.zmb.openapi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ny.zmb.glxt.entity.PmStore;
import com.ny.zmb.openapi.entity.DataResult;
import com.ny.zmb.openapi.entity.PmEp;
import com.ny.zmb.openapi.service.PmEpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * createAuthor : Xmw
 * createTime : 2024-7-29 9:42
 */

@RestController
@CrossOrigin
@RequestMapping("/ep")
@Api(tags  = "1 电子协议相关接口", description = "电子协议相关接口 API")
public class PmEpController {


    @Autowired
    private PmEpService epService;


    @ApiOperation(value = "获取所有的电子协议", notes = "此接口处理的 获取所有的电子协议")
    @RequestMapping("getList")
    public IPage<PmEp> index(
            PmEp pmEp,
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize

    ){

        pmEp.setDel("0");
        IPage<PmEp> page = new Page<>(currentPage, pageSize);
        QueryWrapper<PmEp> pmStoreQueryWrapper = new QueryWrapper<>(pmEp);
        return epService.page(page,pmStoreQueryWrapper);

    }


    @ApiOperation(value = "更新、保存、删除 接口", notes = "此接口处理的 如果传入的有ID 则认为是更新 如果没有传ID则认为是新增、传入ID和Del则是删除")
    @PostMapping("/saveOrUpdate")
    public DataResult<PmEp> saveOrUpdate(PmEp pmEp){

        DataResult<PmEp> pmEpDataResult = new DataResult<>();
        if (pmEp.getId() != null){
            pmEp.setUpdatetime(LocalDateTime.now().toString());
        }
        pmEpDataResult.setCode(epService.saveOrUpdate(pmEp) == true ? "200" : "201");
        return pmEpDataResult;

    }



}
